package com.qlm.controller;

import java.util.List;

import com.jfinal.kit.PropKit;
import com.jfinal.weixin.sdk.api.SnsAccessTokenApi;
import com.qlm.annoation.WeixinAuoth;
import com.qlm.entity.Rank;
import com.qlm.interceptor.WeixinController;
import com.qlm.service.GameMgr;

public class GameController extends WeixinController{

	@WeixinAuoth
	public void index(){
		String appId = PropKit.get("appid");
		String strBackUrl = PropKit.get("authoUrl") + "/game/g";
		String url = SnsAccessTokenApi.getAuthorizeURL(appId, strBackUrl, false);
		redirect(url);
		return ;
	}
	
	public void saveScore(){
		 String header = getRequest().getHeader("Referer");
		 String url = PropKit.get("authoUrl");
		 if(header != null && header.indexOf(url)!= -1){
			 int score = getParaToInt("score",0);
				GameMgr.saveScore(getUser(), score);
				renderJson();
		 }else{
			 
		 }
		
	}
	
	public void g(){
		setJsTicket();
		render("/game/index.jsp");
	}
	
	public void rule(){
		setJsTicket();
		render("/game/rule.jsp");
	}
	
	public void rank(){
		setJsTicket();
		List<Rank> list = GameMgr.getList();
		setAttr("list", list);
		render("/game/rank.jsp");
	}
}
